<template>
  <div class="register-container">
    <!-- 顶部导航栏 -->
    <header class="top-navbar">
      <div class="navbar-content">
        <span class="university-name">四川大学锦江学院</span>
        <span class="auth-status">用户注册</span>
      </div>
    </header>

    <!-- 主体内容 -->
    <main class="register-content">
      <!-- 左侧图片区域 (60%) -->
      <div class="register-banner">
        <div class="banner-overlay">
          <h2 class="banner-title">研究生监考报名系统</h2>
          <p class="banner-subtitle">严谨 · 高效 · 公平 · 公正</p>
        </div>
      </div>

      <!-- 右侧注册区域 (40%) -->
      <div class="register-form-container">
        <div class="register-form">
          <h2 class="form-title">用户注册</h2>

          <!-- 用户名输入 -->
          <div class="input-group">
            <label for="regUsername">用户名</label>
            <input
                id="regUsername"
                type="text"
                v-model="registerForm.username"
                placeholder="请输入学号/工号"
            >
          </div>

          <!-- 密码输入 -->
          <div class="input-group">
            <label for="regPassword">密码</label>
            <input
                id="regPassword"
                type="password"
                v-model="registerForm.password"
                placeholder="请输入密码"
            >
          </div>

          <!-- 确认密码 -->
          <div class="input-group">
            <label for="confirmPassword">确认密码</label>
            <input
                id="confirmPassword"
                type="password"
                v-model="registerForm.confirmPassword"
                placeholder="请再次输入密码"
            >
          </div>

          <!-- 真实姓名 -->
          <div class="input-group">
            <label for="realName">真实姓名</label>
            <input
                id="realName"
                type="text"
                v-model="registerForm.realName"
                placeholder="请输入真实姓名"
            >
          </div>

          <!-- 身份角色选择 -->
          <div class="input-group">
            <label for="regRole">身份角色</label>
            <select
                id="regRole"
                v-model="registerForm.role"
                class="role-select"
            >
              <option value="" disabled selected>请选择您的身份</option>
              <option value="staff">在职在岗教职工</option>
              <option value="director">研公办主任</option>
              <option value="officer">研究生招生考务科长</option>
              <option value="student">学生</option>
            </select>
          </div>

          <!-- 手机号码 -->
          <div class="input-group">
            <label for="phone">手机号码</label>
            <input
                id="phone"
                type="tel"
                v-model="registerForm.phone"
                placeholder="请输入手机号码"
            >
          </div>

          <!-- 邮箱 -->
          <div class="input-group">
            <label for="email">电子邮箱</label>
            <input
                id="email"
                type="email"
                v-model="registerForm.email"
                placeholder="请输入电子邮箱"
            >
          </div>

          <!-- 注册按钮 -->
          <button class="register-btn" @click="handleRegister">注 册</button>

          <!-- 在注册表单底部添加返回登录链接 -->
          <div class="login-link">
            已有账号？<router-link to="/login">返回登录</router-link>
          </div>

          <!-- 温馨提示 -->
          <div class="tip-section">
            <div class="tip-icon">!</div>
            <p>温馨提示：请确保填写的信息真实有效，注册后信息将用于身份验证</p>
          </div>
        </div>
      </div>
    </main>

    <!-- 底部信息 -->
    <footer class="bottom-footer">
      <div class="footer-content">
        <span>四川大学锦江学院</span>
        <span>|</span>
        <span>学校官网：<a href="http://www.scdx.com" target="_blank">www.scdx.com</a></span>
        <span>|</span>
        <span>邮箱：<a href="mailto:12456@qq.com">12456@qq.com</a></span>
      </div>
    </footer>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';

interface RegisterForm {
  username: string;
  password: string;
  confirmPassword: string;
  realName: string;
  role: string;
  phone: string;
  email: string;
}

const router = useRouter();
const registerForm = ref<RegisterForm>({
  username: '',
  password: '',
  confirmPassword: '',
  realName: '',
  role: '',
  phone: '',
  email: ''
});

const validateForm = (): boolean => {
  if (!registerForm.value.username) {
    alert('请输入用户名');
    return false;
  }
  if (!registerForm.value.password) {
    alert('请输入密码');
    return false;
  }
  if (registerForm.value.password !== registerForm.value.confirmPassword) {
    alert('两次输入的密码不一致');
    return false;
  }
  if (!registerForm.value.realName) {
    alert('请输入真实姓名');
    return false;
  }
  if (!registerForm.value.role) {
    alert('请选择身份角色');
    return false;
  }
  return true;
};

const handleRegister = (): void => {
  if (!validateForm()) return;

  console.log('注册信息:', registerForm.value);

  // 模拟注册成功
  alert('注册成功！即将跳转到登录页面');
  router.push('/login');
};
</script>

<style scoped>
.register-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f5f7fa;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

.top-navbar {
  height: 60px;
  background-color: #1a2b4b;
  color: white;
  display: flex;
  align-items: center;
  padding: 0 10%;
}

.navbar-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 500;
}

.auth-status {
  font-weight: normal;
  color: #a8c7ff;
}

.register-content {
  flex: 1;
  display: flex;
}

.register-banner {
  flex: 0 0 60%;
  background: linear-gradient(135deg, #1a3a6c, #2c5282);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.banner-overlay {
  color: white;
  text-align: center;
  padding: 0 15%;
  z-index: 2;
}

.banner-title {
  font-size: 36px;
  font-weight: bold;
  margin-bottom: 20px;
  letter-spacing: 2px;
}

.banner-subtitle {
  font-size: 20px;
  opacity: 0.9;
}

.register-form-container {
  flex: 0 0 40%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background-color: white;
  overflow-y: auto;
}

.register-form {
  width: 100%;
  max-width: 400px;
}

.form-title {
  text-align: center;
  font-size: 24px;
  color: #1a2b4b;
  margin-bottom: 30px;
  font-weight: 600;
}

.input-group {
  margin-bottom: 15px;
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  color: #555;
  font-size: 14px;
}

.input-group input,
.role-select {
  width: 100%;
  height: 42px;
  padding: 0 15px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  font-size: 14px;
  transition: border-color 0.3s;
  background-color: white;
}

.input-group input:focus,
.role-select:focus {
  border-color: #409eff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}

.role-select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 15px center;
  background-size: 16px;
}

.register-btn {
  width: 100%;
  height: 46px;
  background-color: #1a3a6c;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s;
  margin-top: 15px;
}

.register-btn:hover {
  background-color: #2c5282;
}

.login-link {
  text-align: center;
  font-size: 14px;
  color: #666;
  margin-top: 20px;
}

.login-link a {
  color: #1a3a6c;
  text-decoration: none;
  font-weight: 500;
}

.login-link a:hover {
  text-decoration: underline;
}

.tip-section {
  margin-top: 30px;
  padding: 15px;
  background-color: #f0f7ff;
  border-radius: 4px;
  display: flex;
  font-size: 14px;
  color: #1a3a6c;
}

.tip-icon {
  flex: 0 0 24px;
  height: 24px;
  background-color: #1a3a6c;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  font-weight: bold;
}

.bottom-footer {
  height: 50px;
  background-color: #f0f2f5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #666;
}

.footer-content {
  display: flex;
  gap: 15px;
}

.footer-content a {
  color: #1a3a6c;
  text-decoration: none;
}

.footer-content a:hover {
  text-decoration: underline;
}

/* 波浪效果 */
.register-banner::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 20%;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="%23f5f7fa" fill-opacity="1" d="M0,160L48,149.3C96,139,192,117,288,128C384,139,480,181,576,181.3C672,181,768,139,864,112C960,85,1056,75,1152,90.7C1248,107,1344,149,1392,170.7L1440,192L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>');
  background-size: cover;
  background-position: center bottom;
}

/* 响应式设计 */
@media (max-width: 992px) {
  .register-content {
    flex-direction: column;
  }

  .register-banner {
    flex: 0 0 40%;
    min-height: 300px;
  }

  .register-form-container {
    flex: 1;
    padding: 30px 20px;
  }
}

@media (max-width: 576px) {
  .top-navbar {
    padding: 0 5%;
  }

  .banner-title {
    font-size: 28px !important;
  }

  .banner-subtitle {
    font-size: 16px !important;
  }

  .bottom-footer {
    height: auto;
    padding: 10px 0;
  }

  .footer-content {
    flex-direction: column;
    gap: 5px;
    text-align: center;
  }

  .footer-content span:not(:last-child) {
    display: none;
  }
}
</style>